package com.zygh.lz.dao.app;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zygh.lz.entity.app.AppTrailerInfo;
import com.zygh.lz.entity.vo.AppTrailerInfoVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface AppTrailerInfoMapper extends BaseMapper<AppTrailerInfo> {


    @Select("SELECT ati.id,ati.`code`,ati.vehicle_plate as vehiclePlate,ati.phone,ati.Illegal_address as illegalAddress," +
            "ati.park_place as parkPlace," +
            "ati.warning_signal as warningSignal,ati.longitude,ati.latitude,ati.creat_time," +
            "ap.`name`,aft.`name` trafficName,ati.driver_state as driveState,trailer_reason as trailerReason ,reject_reason as rejectReason " +
            "FROM app_trailer_info ati LEFT JOIN app_plate ap ON ati.vehicle_type = ap.`code` LEFT JOIN app_traffic_type aft " +
            "ON ati.traffic_type = aft.`code` WHERE ati.id = #{id} ")
    Map<String, Object> findAppTrailerInfoById(Integer id);


    @Select("<script>" +
            "SELECT id,`code`,vehicle_plate as vehiclePlate,illegal_address as illegalAddress," +
            "DATE_FORMAT(creat_time,'%Y-%m-%d %H:%i:%s') as creatTime ,driver_state as driverState ," +
            "sms_status AS smsStatus " +
            "FROM app_trailer_info " +
            "<where>" +
            "warning_signal = #{warningSignal} and is_del = 0 " +
            "<if test='vehiclePlate != null and vehiclePlate.length &gt; 0'> " +
            "  and vehicle_plate LIKE CONCAT('%',#{vehiclePlate},'%') " +
            "</if>" +
            "<if test='status != null and status.length &gt; 0'> " +
            "  and status= #{status} " +
            "</if>" +
            "<if test='code != null and code.length &gt; 0'> " +
            "  and park_code = #{code} " +
            "</if>" +
            "<if test='startTime != null and startTime.length &gt; 0'> " +
            "  and creat_time BETWEEN CONCAT(#{startTime},' 00:00:00') AND CONCAT(#{endTime},' 23:59:59') " +
            "</if>" +
            "<if test='driverState != null'> " +
            "  and driver_state =  #{driverState} " +
            "</if>" +
            "ORDER BY creat_time DESC" +
            "</where>" +
            "</script>")
    List<Map<String, Object>> findTrailerInfo(@Param("warningSignal") String warningSignal,
                                              @Param("vehiclePlate") String vehiclePlate,
                                              @Param("status") Integer status,
                                              @Param("code") Integer code,
                                              @Param("startTime") String startTime, @Param("endTime") String endTime,
                                              @Param("driverState") Integer driverState);

    List<AppTrailerInfoVO> findTrailerByBoard();

    void updateSignBoard(@Param("codeList") List<String> codeList);
}
